﻿// BizElements generated entity and metadata classes for AppLog.
using System;
using System.Data;
using System.Configuration;
using BizElements.Core;

namespace BizElements.BusinessLayer
{
	/// <summary>
	/// Entity model class for the table/view 'AppLog'.
	/// </summary>
	[Serializable]
	internal class AppLogEntity : EntityModelBase
	{
		#region Private members.

		// Members mapped to database columns.
		private int? logID;
		private string title;
		private string message;
		private string actorID;
		private string actorName;
		private string objectType;
		private string objectID;
		private string category;
		private DateTime? timestamp;
		private string machineName;
		private string appDomainName;
		private string formattedMessage;
		private byte? status;
		
		
		#endregion

		#region Protected properties.
    
		// Properties mapped to database columns.    
		/// <summary>
		/// Gets or sets the value which is mapped to the field 'LogID'.
		/// </summary>
		protected int? _LogID
		{
			get
			{
				return this.logID;
			}
			set
			{
				if (this.EntityState == EntityState.Synchronized)
				{
					if ((!value.HasValue != !this.logID.HasValue) || (value.HasValue && (value.Value != this.logID.Value)))
						this.EntityState = EntityState.OutOfSync;
				}
				this.logID = value;
			}
		}

		/// <summary>
		/// Gets or sets the value which is mapped to the field 'Title'.
		/// </summary>
		protected string _Title
		{
			get
			{
				return this.title;
			}
			set
			{
				if (this.EntityState == EntityState.Synchronized)
				{
					if (value != this.title)
						this.EntityState = EntityState.OutOfSync;
				}
				this.title = value;
			}
		}

		/// <summary>
		/// Gets or sets the value which is mapped to the field 'Message'.
		/// </summary>
		protected string _Message
		{
			get
			{
				return this.message;
			}
			set
			{
				if (this.EntityState == EntityState.Synchronized)
				{
					if (value != this.message)
						this.EntityState = EntityState.OutOfSync;
				}
				this.message = value;
			}
		}

		/// <summary>
		/// Gets or sets the value which is mapped to the field 'ActorID'.
		/// </summary>
		protected string _ActorID
		{
			get
			{
				return this.actorID;
			}
			set
			{
				if (this.EntityState == EntityState.Synchronized)
				{
					if (value != this.actorID)
						this.EntityState = EntityState.OutOfSync;
				}
				this.actorID = value;
			}
		}

		/// <summary>
		/// Gets or sets the value which is mapped to the field 'ActorName'.
		/// </summary>
		protected string _ActorName
		{
			get
			{
				return this.actorName;
			}
			set
			{
				if (this.EntityState == EntityState.Synchronized)
				{
					if (value != this.actorName)
						this.EntityState = EntityState.OutOfSync;
				}
				this.actorName = value;
			}
		}

		/// <summary>
		/// Gets or sets the value which is mapped to the field 'ObjectType'.
		/// </summary>
		protected string _ObjectType
		{
			get
			{
				return this.objectType;
			}
			set
			{
				if (this.EntityState == EntityState.Synchronized)
				{
					if (value != this.objectType)
						this.EntityState = EntityState.OutOfSync;
				}
				this.objectType = value;
			}
		}

		/// <summary>
		/// Gets or sets the value which is mapped to the field 'ObjectID'.
		/// </summary>
		protected string _ObjectID
		{
			get
			{
				return this.objectID;
			}
			set
			{
				if (this.EntityState == EntityState.Synchronized)
				{
					if (value != this.objectID)
						this.EntityState = EntityState.OutOfSync;
				}
				this.objectID = value;
			}
		}

		/// <summary>
		/// Gets or sets the value which is mapped to the field 'Category'.
		/// </summary>
		protected string _Category
		{
			get
			{
				return this.category;
			}
			set
			{
				if (this.EntityState == EntityState.Synchronized)
				{
					if (value != this.category)
						this.EntityState = EntityState.OutOfSync;
				}
				this.category = value;
			}
		}

		/// <summary>
		/// Gets or sets the value which is mapped to the field 'Timestamp'.
		/// </summary>
		protected DateTime? _Timestamp
		{
			get
			{
				return this.timestamp;
			}
			set
			{
				if (this.EntityState == EntityState.Synchronized)
				{
					if ((!value.HasValue != !this.timestamp.HasValue) || (value.HasValue && (value.Value != this.timestamp.Value)))
						this.EntityState = EntityState.OutOfSync;
				}
				this.timestamp = value;
			}
		}

		/// <summary>
		/// Gets or sets the value which is mapped to the field 'MachineName'.
		/// </summary>
		protected string _MachineName
		{
			get
			{
				return this.machineName;
			}
			set
			{
				if (this.EntityState == EntityState.Synchronized)
				{
					if (value != this.machineName)
						this.EntityState = EntityState.OutOfSync;
				}
				this.machineName = value;
			}
		}

		/// <summary>
		/// Gets or sets the value which is mapped to the field 'AppDomainName'.
		/// </summary>
		protected string _AppDomainName
		{
			get
			{
				return this.appDomainName;
			}
			set
			{
				if (this.EntityState == EntityState.Synchronized)
				{
					if (value != this.appDomainName)
						this.EntityState = EntityState.OutOfSync;
				}
				this.appDomainName = value;
			}
		}

		/// <summary>
		/// Gets or sets the value which is mapped to the field 'FormattedMessage'.
		/// </summary>
		protected string _FormattedMessage
		{
			get
			{
				return this.formattedMessage;
			}
			set
			{
				if (this.EntityState == EntityState.Synchronized)
				{
					if (value != this.formattedMessage)
						this.EntityState = EntityState.OutOfSync;
				}
				this.formattedMessage = value;
			}
		}

		/// <summary>
		/// Gets or sets the value which is mapped to the field 'Status'.
		/// </summary>
		protected byte? _Status
		{
			get
			{
				return this.status;
			}
			set
			{
				if (this.EntityState == EntityState.Synchronized)
				{
					if ((!value.HasValue != !this.status.HasValue) || (value.HasValue && (value.Value != this.status.Value)))
						this.EntityState = EntityState.OutOfSync;
				}
				this.status = value;
			}
		}

		
		#endregion

		#region Constructors.

		/// <summary>
		/// Default constructor.
		/// </summary>
		public AppLogEntity() 
			 : base(new AppLogMeta())
		{
		}

		/// <summary>
		/// Constructor. Initalizes Table property with the specified (shared) instance.
		/// </summary>
		/// <param name="dbTable">Metadata for table/view to which the entity belongs to.</param>
		public AppLogEntity(AppLogMeta dbTable)
			: base(dbTable)
		{
		}
		
		/// <summary>
		/// Constructor. Initializes primary key. Useful for methods that don't require other values (eg. DeleteOne, SelectOne).
		/// </summary>
		public AppLogEntity(int logID) 
			 : base(new AppLogMeta())
		{
			_LogID = logID;
		}

		/// <summary>
		/// Constructor. Initializes primary key. Useful for methods that don't require other values (eg. DeleteOne, SelectOne).
		/// </summary>
		public AppLogEntity(AppLogMeta dbTable, int logID)
			 : base(dbTable)
		{
			_LogID = logID;
		}

		/// <summary>
		/// Constructor. Initializes members with the values in the given DataRow.
		/// </summary>
		/// <param name="row">DataRow with required columns.</param>
		/// <remarks>If row's state is <see cref="DataRowState.Unchanged"/> the entity's state will be set to <see cref="EntityState.Synchronized"/>. Other states are ignored.</remarks>
		public AppLogEntity(DataRow row) 
			 : base(new AppLogMeta())
		{
			FromDataRow(row);
		}

		/// <summary>
		/// Constructor. Initializes members with the values in the given DataRow.
		/// </summary>
		/// <param name="dbTable">Metadata for table/view to which the entity belongs to.</param>
		/// <param name="row">DataRow with required columns.</param>
		/// <remarks>If row's state is <see cref="DataRowState.Unchanged"/> the entity's state will be set to <see cref="EntityState.Synchronized"/>. Other states are ignored.</remarks>
		public AppLogEntity(AppLogMeta dbTable, DataRow row) 
			 : base(dbTable)
		{
			FromDataRow(row);
		}

		/// <summary>
		/// Copy constructor.
		/// </summary>
		/// <param name="existing">Instance of AppLogEntity.</param>
		public AppLogEntity(AppLogEntity existing) 
			 : base(existing.Table)
		{
			 FromExistingEntity(existing);
		}
    
		static readonly Type DbTableClass = typeof(AppLogMeta);

		/// <summary>
		/// Initializes all members of AppLogEntity and base EntityModelBase class. This is the fastest way to initialize entity with data from database.
		/// </summary>
		private AppLogEntity(IDbTable table, EntityState entityState, int? logID, string title, string message, string actorID, string actorName, string objectType, string objectID, string category, DateTime? timestamp, string machineName, string appDomainName, string formattedMessage, byte? status) 
			 : base(table, DbTableClass, entityState)
		{
			this.logID = logID;
			this.title = title;
			this.message = message;
			this.actorID = actorID;
			this.actorName = actorName;
			this.objectType = objectType;
			this.objectID = objectID;
			this.category = category;
			this.timestamp = timestamp;
			this.machineName = machineName;
			this.appDomainName = appDomainName;
			this.formattedMessage = formattedMessage;
			this.status = status;
		}

		/// <summary>
		/// Initializes all members mapped to fields.
		/// </summary>
		protected void Init(int? logID, string title, string message, string actorID, string actorName, string objectType, string objectID, string category, DateTime? timestamp, string machineName, string appDomainName, string formattedMessage, byte? status)
		{
			_LogID = logID;
			_Title = title;
			_Message = message;
			_ActorID = actorID;
			_ActorName = actorName;
			_ObjectType = objectType;
			_ObjectID = objectID;
			_Category = category;
			_Timestamp = timestamp;
			_MachineName = machineName;
			_AppDomainName = appDomainName;
			_FormattedMessage = formattedMessage;
			_Status = status;
		}

		#endregion

		#region Methods.

		/// <summary>
		/// Gets the value(s) that uniquely identifiy an entity.
		/// In the order as specified in accompanying IDbTable metadata class.
		/// NULL if the parent table/view doesn't have a primary key constraint or the required fields are not set.
		/// </summary>
		public override object[] GetPrimaryKeyValue()
		{
			if (_LogID != null)
				return new object[] {_LogID.Value};
			else
				return null;
		}

		/// <summary>
		/// Initializes entity members with data stored in the given DataRow.
		/// </summary>
		/// <param name="row">DataRow with the required columns.</param>
		/// <remarks>If row's state is <see cref="DataRowState.Unchanged"/> the entity's state will be set to <see cref="EntityState.Synchronized"/>. Other states are ignored.</remarks>
		public override void FromDataRow(DataRow row)
		{
			object currentColumnValue;
      
			currentColumnValue = TryGetColumnValue(row, this.Table.LogID.PropertyName);
			_LogID = (currentColumnValue != DBNull.Value) ? (int?) Convert.ToInt32(currentColumnValue) : null;
      
			currentColumnValue = TryGetColumnValue(row, this.Table.Title.PropertyName);
			_Title = (currentColumnValue != DBNull.Value) ? (string) Convert.ToString(currentColumnValue) : null;
      
			currentColumnValue = TryGetColumnValue(row, this.Table.Message.PropertyName);
			_Message = (currentColumnValue != DBNull.Value) ? (string) Convert.ToString(currentColumnValue) : null;
      
			currentColumnValue = TryGetColumnValue(row, this.Table.ActorID.PropertyName);
			_ActorID = (currentColumnValue != DBNull.Value) ? (string) Convert.ToString(currentColumnValue) : null;
      
			currentColumnValue = TryGetColumnValue(row, this.Table.ActorName.PropertyName);
			_ActorName = (currentColumnValue != DBNull.Value) ? (string) Convert.ToString(currentColumnValue) : null;
      
			currentColumnValue = TryGetColumnValue(row, this.Table.ObjectType.PropertyName);
			_ObjectType = (currentColumnValue != DBNull.Value) ? (string) Convert.ToString(currentColumnValue) : null;
      
			currentColumnValue = TryGetColumnValue(row, this.Table.ObjectID.PropertyName);
			_ObjectID = (currentColumnValue != DBNull.Value) ? (string) Convert.ToString(currentColumnValue) : null;
      
			currentColumnValue = TryGetColumnValue(row, this.Table.Category.PropertyName);
			_Category = (currentColumnValue != DBNull.Value) ? (string) Convert.ToString(currentColumnValue) : null;
      
			currentColumnValue = TryGetColumnValue(row, this.Table.Timestamp.PropertyName);
			_Timestamp = (currentColumnValue != DBNull.Value) ? (DateTime?) Convert.ToDateTime(currentColumnValue) : null;
      
			currentColumnValue = TryGetColumnValue(row, this.Table.MachineName.PropertyName);
			_MachineName = (currentColumnValue != DBNull.Value) ? (string) Convert.ToString(currentColumnValue) : null;
      
			currentColumnValue = TryGetColumnValue(row, this.Table.AppDomainName.PropertyName);
			_AppDomainName = (currentColumnValue != DBNull.Value) ? (string) Convert.ToString(currentColumnValue) : null;
      
			currentColumnValue = TryGetColumnValue(row, this.Table.FormattedMessage.PropertyName);
			_FormattedMessage = (currentColumnValue != DBNull.Value) ? (string) Convert.ToString(currentColumnValue) : null;
      
			currentColumnValue = TryGetColumnValue(row, this.Table.Status.PropertyName);
			_Status = (currentColumnValue != DBNull.Value) ? (byte?) Convert.ToByte(currentColumnValue) : null;
      
			bool setEntityStateToSynchronized = (row.RowState == DataRowState.Unchanged);
			if (setEntityStateToSynchronized)
				this.EntityState = EntityState.Synchronized;
		}

		private static object TryGetColumnValue(DataRow row, string columnName)
		{
			int colIdx = row.Table.Columns.IndexOf(columnName);
			return (colIdx >= 0) ? row[colIdx] : null;
		}

		private static object GetColumnValue(DataRow row, IDbColumn column)
		{
			int colIdx = row.Table.Columns.IndexOf(column.Alias);
			if (colIdx < 0)
				colIdx = row.Table.Columns.IndexOf(column.ColumnName);
			if (colIdx < 0)
				throw new ArgumentException("DataTable doesn't contain the specified column (" + column.ColumnName + ").");

			return row[colIdx];
		}

		/// <summary>
		/// Initializes entity members with data stored in the given DataRow.
		/// </summary>
		/// <param name="row">DataRow with all or some of the columns defined in meta data.</param>
		/// <param name="fieldMetaData"><see cref="IDbTable"/> meta data object which links ADO.NET row columns to entity properties.</param>
		/// <remarks>If row's state is <see cref="DataRowState.Unchanged"/> the entity's state will be set to <see cref="EntityState.Synchronized"/>. Other states are ignored.</remarks>
		public override void FromDataRow(DataRow row, IDbTable fieldMetaData)
		{
			IDbColumn currentColumn;
			object currentColumnValue;
      
			currentColumn = fieldMetaData.Columns.GetByPropertyName(this.Table.LogID.PropertyName);
			currentColumnValue = (currentColumn != null) ? GetColumnValue(row, currentColumn) : DBNull.Value;
			_LogID = (currentColumnValue != DBNull.Value) ? (int?) Convert.ToInt32(currentColumnValue) : null;
      
			currentColumn = fieldMetaData.Columns.GetByPropertyName(this.Table.Title.PropertyName);
			currentColumnValue = (currentColumn != null) ? GetColumnValue(row, currentColumn) : DBNull.Value;
			_Title = (currentColumnValue != DBNull.Value) ? (string) Convert.ToString(currentColumnValue) : null;
      
			currentColumn = fieldMetaData.Columns.GetByPropertyName(this.Table.Message.PropertyName);
			currentColumnValue = (currentColumn != null) ? GetColumnValue(row, currentColumn) : DBNull.Value;
			_Message = (currentColumnValue != DBNull.Value) ? (string) Convert.ToString(currentColumnValue) : null;
      
			currentColumn = fieldMetaData.Columns.GetByPropertyName(this.Table.ActorID.PropertyName);
			currentColumnValue = (currentColumn != null) ? GetColumnValue(row, currentColumn) : DBNull.Value;
			_ActorID = (currentColumnValue != DBNull.Value) ? (string) Convert.ToString(currentColumnValue) : null;
      
			currentColumn = fieldMetaData.Columns.GetByPropertyName(this.Table.ActorName.PropertyName);
			currentColumnValue = (currentColumn != null) ? GetColumnValue(row, currentColumn) : DBNull.Value;
			_ActorName = (currentColumnValue != DBNull.Value) ? (string) Convert.ToString(currentColumnValue) : null;
      
			currentColumn = fieldMetaData.Columns.GetByPropertyName(this.Table.ObjectType.PropertyName);
			currentColumnValue = (currentColumn != null) ? GetColumnValue(row, currentColumn) : DBNull.Value;
			_ObjectType = (currentColumnValue != DBNull.Value) ? (string) Convert.ToString(currentColumnValue) : null;
      
			currentColumn = fieldMetaData.Columns.GetByPropertyName(this.Table.ObjectID.PropertyName);
			currentColumnValue = (currentColumn != null) ? GetColumnValue(row, currentColumn) : DBNull.Value;
			_ObjectID = (currentColumnValue != DBNull.Value) ? (string) Convert.ToString(currentColumnValue) : null;
      
			currentColumn = fieldMetaData.Columns.GetByPropertyName(this.Table.Category.PropertyName);
			currentColumnValue = (currentColumn != null) ? GetColumnValue(row, currentColumn) : DBNull.Value;
			_Category = (currentColumnValue != DBNull.Value) ? (string) Convert.ToString(currentColumnValue) : null;
      
			currentColumn = fieldMetaData.Columns.GetByPropertyName(this.Table.Timestamp.PropertyName);
			currentColumnValue = (currentColumn != null) ? GetColumnValue(row, currentColumn) : DBNull.Value;
			_Timestamp = (currentColumnValue != DBNull.Value) ? (DateTime?) Convert.ToDateTime(currentColumnValue) : null;
      
			currentColumn = fieldMetaData.Columns.GetByPropertyName(this.Table.MachineName.PropertyName);
			currentColumnValue = (currentColumn != null) ? GetColumnValue(row, currentColumn) : DBNull.Value;
			_MachineName = (currentColumnValue != DBNull.Value) ? (string) Convert.ToString(currentColumnValue) : null;
      
			currentColumn = fieldMetaData.Columns.GetByPropertyName(this.Table.AppDomainName.PropertyName);
			currentColumnValue = (currentColumn != null) ? GetColumnValue(row, currentColumn) : DBNull.Value;
			_AppDomainName = (currentColumnValue != DBNull.Value) ? (string) Convert.ToString(currentColumnValue) : null;
      
			currentColumn = fieldMetaData.Columns.GetByPropertyName(this.Table.FormattedMessage.PropertyName);
			currentColumnValue = (currentColumn != null) ? GetColumnValue(row, currentColumn) : DBNull.Value;
			_FormattedMessage = (currentColumnValue != DBNull.Value) ? (string) Convert.ToString(currentColumnValue) : null;
      
			currentColumn = fieldMetaData.Columns.GetByPropertyName(this.Table.Status.PropertyName);
			currentColumnValue = (currentColumn != null) ? GetColumnValue(row, currentColumn) : DBNull.Value;
			_Status = (currentColumnValue != DBNull.Value) ? (byte?) Convert.ToByte(currentColumnValue) : null;
      
			bool setEntityStateToSynchronized = (row.RowState == DataRowState.Unchanged);
			if (setEntityStateToSynchronized)
				this.EntityState = EntityState.Synchronized;
		}

		/// <summary>
		/// Converts the given DataRow to AppLogEntity.
		/// </summary>
		/// <param name="row">DataRow with required columns.</param>
		/// <remarks>If row's state is <see cref="DataRowState.Unchanged"/> the entity's state will be set to <see cref="EntityState.Synchronized"/>. Other states are ignored.</remarks>
		public static explicit operator AppLogEntity(DataRow row)
		{
			return new AppLogEntity(row);
		}

		/// <summary>
		/// Creates an array of objects containing entity data.
		/// </summary>
		/// <returns>Entity values.</returns>
		public override object[] ToObjectArray()
		{
			object[] values = new object[13];
      
			values[0] = (_LogID != null) ? (object) _LogID.Value : null;
			values[1] = (_Title != null) ? (object) _Title : null;
			values[2] = (_Message != null) ? (object) _Message : null;
			values[3] = (_ActorID != null) ? (object) _ActorID : null;
			values[4] = (_ActorName != null) ? (object) _ActorName : null;
			values[5] = (_ObjectType != null) ? (object) _ObjectType : null;
			values[6] = (_ObjectID != null) ? (object) _ObjectID : null;
			values[7] = (_Category != null) ? (object) _Category : null;
			values[8] = (_Timestamp != null) ? (object) _Timestamp.Value : null;
			values[9] = (_MachineName != null) ? (object) _MachineName : null;
			values[10] = (_AppDomainName != null) ? (object) _AppDomainName : null;
			values[11] = (_FormattedMessage != null) ? (object) _FormattedMessage : null;
			values[12] = (_Status != null) ? (object) _Status.Value : null;
			
			return values;
		}

		/// <summary>
		/// Initializes entity members with the given values.
		/// </summary>
		/// <param name="entityValues">Array with the required values.</param>
		public override void FromObjectArray(object[] entityValues)
		{
			_LogID = (entityValues[0] != null) ? (int?) Convert.ToInt32(entityValues[0]) : null;
			_Title = (entityValues[1] != null) ? (string) Convert.ToString(entityValues[1]) : null;
			_Message = (entityValues[2] != null) ? (string) Convert.ToString(entityValues[2]) : null;
			_ActorID = (entityValues[3] != null) ? (string) Convert.ToString(entityValues[3]) : null;
			_ActorName = (entityValues[4] != null) ? (string) Convert.ToString(entityValues[4]) : null;
			_ObjectType = (entityValues[5] != null) ? (string) Convert.ToString(entityValues[5]) : null;
			_ObjectID = (entityValues[6] != null) ? (string) Convert.ToString(entityValues[6]) : null;
			_Category = (entityValues[7] != null) ? (string) Convert.ToString(entityValues[7]) : null;
			_Timestamp = (entityValues[8] != null) ? (DateTime?) Convert.ToDateTime(entityValues[8]) : null;
			_MachineName = (entityValues[9] != null) ? (string) Convert.ToString(entityValues[9]) : null;
			_AppDomainName = (entityValues[10] != null) ? (string) Convert.ToString(entityValues[10]) : null;
			_FormattedMessage = (entityValues[11] != null) ? (string) Convert.ToString(entityValues[11]) : null;
			_Status = (entityValues[12] != null) ? (byte?) Convert.ToByte(entityValues[12]) : null;
		}

		/// <summary>
		/// Gets the parent entity defined by the given foreign key.
		/// </summary>
		/// <param name="foreignKey">FK which must be defined in the AppLogMeta class or an exception is generated.</param>
		/// <returns>Parent entity. NULL if the FK fields haven't been set or if the entity with the given key values doesn't exist.</returns>
		public override IEntity GetParent(DbRelation foreignKey)
		{
			throw new Exception("No foreign keys are defined in the AppLogMeta class.");
		}

		/// <summary>
		/// Sets the given value into the member that represents the parent entity defined by the foreign key.
		/// </summary>
		/// <param name="foreignKey">FK which must be defined in the CFunctionsMeta class or an exception is generated.</param>
		/// <param name="entity">Parent entity. May be NULL. Must be an instance of the CFunctionsEntity or a derived class.</param>
		public override void SetParent(DbRelation foreignKey, IEntity entity)
		{
			throw new Exception("No foreign keys are defined in the AppLogMeta class.");
		}

		#endregion

		/// <summary>
		/// Gets typed IDbTable object for the entity's table/view.
		/// </summary>
		public AppLogMeta Table
		{
			get {return (AppLogMeta) _Table;}
		}

		#region Public properties mapped to database columns.
		
		/// <summary>
		/// Gets or sets the value which is mapped to the non-nullable field 'LogID'.
		/// If null-check is enabled a NoNullAllowedException is thrown if getter is used before the value has been set.
		/// </summary>
		public virtual int LogID
		{
			get
			{
				if (_LogID == null)
				{
					if (this.NullCheckEnabled)
						throw new NoNullAllowedException("AppLogEntity.get_LogID: LogID is not set yet.");
					else
						return default(int);
				}
        
				return _LogID.Value;
			}
			set
			{
				_LogID = value;
			}
		}
		
		/// <summary>
		/// Gets or sets the value which is mapped to the nullable field 'Title'.
		/// </summary>
		public virtual string Title
		{
			get
			{
				return _Title;
			}
			set
			{
				_Title = value;
			}
		}
		
		/// <summary>
		/// Gets or sets the value which is mapped to the nullable field 'Message'.
		/// </summary>
		public virtual string Message
		{
			get
			{
				return _Message;
			}
			set
			{
				_Message = value;
			}
		}
		
		/// <summary>
		/// Gets or sets the value which is mapped to the nullable field 'ActorID'.
		/// </summary>
		public virtual string ActorID
		{
			get
			{
				return _ActorID;
			}
			set
			{
				_ActorID = value;
			}
		}
		
		/// <summary>
		/// Gets or sets the value which is mapped to the nullable field 'ActorName'.
		/// </summary>
		public virtual string ActorName
		{
			get
			{
				return _ActorName;
			}
			set
			{
				_ActorName = value;
			}
		}
		
		/// <summary>
		/// Gets or sets the value which is mapped to the nullable field 'ObjectType'.
		/// </summary>
		public virtual string ObjectType
		{
			get
			{
				return _ObjectType;
			}
			set
			{
				_ObjectType = value;
			}
		}
		
		/// <summary>
		/// Gets or sets the value which is mapped to the nullable field 'ObjectID'.
		/// </summary>
		public virtual string ObjectID
		{
			get
			{
				return _ObjectID;
			}
			set
			{
				_ObjectID = value;
			}
		}
		
		/// <summary>
		/// Gets or sets the value which is mapped to the nullable field 'Category'.
		/// </summary>
		public virtual string Category
		{
			get
			{
				return _Category;
			}
			set
			{
				_Category = value;
			}
		}
		
		/// <summary>
		/// Gets or sets the value which is mapped to the nullable field 'Timestamp'.
		/// </summary>
		public virtual DateTime? Timestamp
		{
			get
			{
				return _Timestamp;
			}
			set
			{
				_Timestamp = value;
			}
		}
		
		/// <summary>
		/// Gets or sets the value which is mapped to the nullable field 'MachineName'.
		/// </summary>
		public virtual string MachineName
		{
			get
			{
				return _MachineName;
			}
			set
			{
				_MachineName = value;
			}
		}
		
		/// <summary>
		/// Gets or sets the value which is mapped to the nullable field 'AppDomainName'.
		/// </summary>
		public virtual string AppDomainName
		{
			get
			{
				return _AppDomainName;
			}
			set
			{
				_AppDomainName = value;
			}
		}
		
		/// <summary>
		/// Gets or sets the value which is mapped to the nullable field 'FormattedMessage'.
		/// </summary>
		public virtual string FormattedMessage
		{
			get
			{
				return _FormattedMessage;
			}
			set
			{
				_FormattedMessage = value;
			}
		}
		
		/// <summary>
		/// Gets or sets the value which is mapped to the non-nullable field 'Status'.
		/// If null-check is enabled a NoNullAllowedException is thrown if getter is used before the value has been set.
		/// </summary>
		public virtual byte Status
		{
			get
			{
				if (_Status == null)
				{
					if (this.NullCheckEnabled)
						throw new NoNullAllowedException("AppLogEntity.get_Status: Status is not set yet.");
					else
						return default(byte);
				}
        
				return _Status.Value;
			}
			set
			{
				_Status = value;
			}
		}
		
		#endregion
		
		#region NewEntity static methods suitable for usage in EntityBuilder<T>.

		/// <summary>Creates new entity and initializes all members of with the given values.</summary>
		/// <param name="table">Metadata for table/view to which the entity belongs to.</param>
		/// <param name="entityState">Indicates the state of entity with regard to data-source.</param>
		/// <param name="values">Array which contains values for all properties mapped to database columns in the following order: LogID, Title, Message, ActorID, ActorName, ObjectType, ObjectID, Category, Timestamp, MachineName, AppDomainName, FormattedMessage, Status.</param>
		/// <remarks>This is the fastest method to initialize an entity as it directly initializes all members of base and derived class, 
		/// skips all validation checks and doesn't attempt to convert provided value data types. The method is typically used in combination 
		/// with IDataConverter objects which retrieve property values directly from IDataReader objects.</remarks>
		public static AppLogEntity NewEntity(IDbTable table, EntityState entityState, object[] values)
		{
			return new AppLogEntity(table, entityState, (int)values[0], (string)ReplaceDbNull(values[1]), (string)ReplaceDbNull(values[2]), (string)ReplaceDbNull(values[3]), (string)ReplaceDbNull(values[4]), (string)ReplaceDbNull(values[5]), (string)ReplaceDbNull(values[6]), (string)ReplaceDbNull(values[7]), CastTo<DateTime>(values[8]), (string)ReplaceDbNull(values[9]), (string)ReplaceDbNull(values[10]), (string)ReplaceDbNull(values[11]), (byte)values[12]);
		}

		/// <summary>Creates new entity and initializes members for which values are defined in the array.</summary>
		/// <param name="table">Metadata for table/view to which the entity belongs to.</param>
		/// <param name="entityState">Indicates the state of entity with regard to data-source.</param>
		/// <param name="values">Array which contains values or nulls for all properties mapped to database columns in the following order: LogID, Title, Message, ActorID, ActorName, ObjectType, ObjectID, Category, Timestamp, MachineName, AppDomainName, FormattedMessage, Status.</param>
		/// <remarks>This is the fastest method to initialize an entity as it directly initializes all members of base and derived class, 
		/// skips all validation checks and doesn't attempt to convert provided value data types. The method is typically used in combination 
		/// with IObjectReader objects which retrieve property values directly from IDataReader objects.</remarks>
		public static AppLogEntity NewPartialEntity(IDbTable table, EntityState entityState, object[] values)
		{
			return new AppLogEntity(table, entityState, CastTo<int>(values[0]), (string)ReplaceDbNull(values[1]), (string)ReplaceDbNull(values[2]), (string)ReplaceDbNull(values[3]), (string)ReplaceDbNull(values[4]), (string)ReplaceDbNull(values[5]), (string)ReplaceDbNull(values[6]), (string)ReplaceDbNull(values[7]), CastTo<DateTime>(values[8]), (string)ReplaceDbNull(values[9]), (string)ReplaceDbNull(values[10]), (string)ReplaceDbNull(values[11]), CastTo<byte>(values[12]));
		}

		private static T? CastTo<T>(object val)
			where T : struct
		{
			if (IsNull(val))
				return null;
			else
				return (T)val;
		}

		private static bool IsNull(object val)
		{
			return (val == DBNull.Value || val == null);
		}
    
		private static object ReplaceDbNull(object dbValue)
		{
			return (dbValue != DBNull.Value) ? dbValue : null;
		}

		#endregion
	}

	/// <summary>
	/// Typed IDbTable class for the table/view 'AppLog'.
	/// </summary>
	[Serializable]
    internal sealed class AppLogMeta : SealedDbTable
	{
		static AppLogMeta()
		{
			ReadSequenceOverrideFromConfig();
			ReadColumnNamesFromConfig();
			ImmutableColumnProperties = CreateImmutableColumnProperties();
			ImmutableTableProperties = CreateImmutableTableProperties();
		}
    
		#region Configuration.
		
		static readonly string[] SequenceNameOverrides = new string[13];
		static readonly bool?[] AutoIncrementOverrides = new bool?[13];
    
		private static void ReadSequenceOverrideFromConfig()
		{
			SequenceNameOverrides[0] = ConfigurationManager.AppSettings["BizElements.BusinessLayer.AppLog.LogID.SequenceName"];
			AutoIncrementOverrides[0] = (SequenceNameOverrides[0] != null) ? (bool?)true : null;
			SequenceNameOverrides[1] = ConfigurationManager.AppSettings["BizElements.BusinessLayer.AppLog.Title.SequenceName"];
			AutoIncrementOverrides[1] = (SequenceNameOverrides[1] != null) ? (bool?)true : null;
			SequenceNameOverrides[2] = ConfigurationManager.AppSettings["BizElements.BusinessLayer.AppLog.Message.SequenceName"];
			AutoIncrementOverrides[2] = (SequenceNameOverrides[2] != null) ? (bool?)true : null;
			SequenceNameOverrides[3] = ConfigurationManager.AppSettings["BizElements.BusinessLayer.AppLog.ActorID.SequenceName"];
			AutoIncrementOverrides[3] = (SequenceNameOverrides[3] != null) ? (bool?)true : null;
			SequenceNameOverrides[4] = ConfigurationManager.AppSettings["BizElements.BusinessLayer.AppLog.ActorName.SequenceName"];
			AutoIncrementOverrides[4] = (SequenceNameOverrides[4] != null) ? (bool?)true : null;
			SequenceNameOverrides[5] = ConfigurationManager.AppSettings["BizElements.BusinessLayer.AppLog.ObjectType.SequenceName"];
			AutoIncrementOverrides[5] = (SequenceNameOverrides[5] != null) ? (bool?)true : null;
			SequenceNameOverrides[6] = ConfigurationManager.AppSettings["BizElements.BusinessLayer.AppLog.ObjectID.SequenceName"];
			AutoIncrementOverrides[6] = (SequenceNameOverrides[6] != null) ? (bool?)true : null;
			SequenceNameOverrides[7] = ConfigurationManager.AppSettings["BizElements.BusinessLayer.AppLog.Category.SequenceName"];
			AutoIncrementOverrides[7] = (SequenceNameOverrides[7] != null) ? (bool?)true : null;
			SequenceNameOverrides[8] = ConfigurationManager.AppSettings["BizElements.BusinessLayer.AppLog.Timestamp.SequenceName"];
			AutoIncrementOverrides[8] = (SequenceNameOverrides[8] != null) ? (bool?)true : null;
			SequenceNameOverrides[9] = ConfigurationManager.AppSettings["BizElements.BusinessLayer.AppLog.MachineName.SequenceName"];
			AutoIncrementOverrides[9] = (SequenceNameOverrides[9] != null) ? (bool?)true : null;
			SequenceNameOverrides[10] = ConfigurationManager.AppSettings["BizElements.BusinessLayer.AppLog.AppDomainName.SequenceName"];
			AutoIncrementOverrides[10] = (SequenceNameOverrides[10] != null) ? (bool?)true : null;
			SequenceNameOverrides[11] = ConfigurationManager.AppSettings["BizElements.BusinessLayer.AppLog.FormattedMessage.SequenceName"];
			AutoIncrementOverrides[11] = (SequenceNameOverrides[11] != null) ? (bool?)true : null;
			SequenceNameOverrides[12] = ConfigurationManager.AppSettings["BizElements.BusinessLayer.AppLog.Status.SequenceName"];
			AutoIncrementOverrides[12] = (SequenceNameOverrides[12] != null) ? (bool?)true : null;
		}

		static readonly string[] ColumnNames = new string[13];

		private static void ReadColumnNamesFromConfig()
		{
			ColumnNames[0] = BizElements.BusinessLayer.AppLogCatalog.GetColumnNameOverride("AppLog", "LogID") ?? "LogID";
			ColumnNames[1] = BizElements.BusinessLayer.AppLogCatalog.GetColumnNameOverride("AppLog", "Title") ?? "Title";
			ColumnNames[2] = BizElements.BusinessLayer.AppLogCatalog.GetColumnNameOverride("AppLog", "Message") ?? "Message";
			ColumnNames[3] = BizElements.BusinessLayer.AppLogCatalog.GetColumnNameOverride("AppLog", "ActorID") ?? "ActorID";
			ColumnNames[4] = BizElements.BusinessLayer.AppLogCatalog.GetColumnNameOverride("AppLog", "ActorName") ?? "ActorName";
			ColumnNames[5] = BizElements.BusinessLayer.AppLogCatalog.GetColumnNameOverride("AppLog", "ObjectType") ?? "ObjectType";
			ColumnNames[6] = BizElements.BusinessLayer.AppLogCatalog.GetColumnNameOverride("AppLog", "ObjectID") ?? "ObjectID";
			ColumnNames[7] = BizElements.BusinessLayer.AppLogCatalog.GetColumnNameOverride("AppLog", "Category") ?? "Category";
			ColumnNames[8] = BizElements.BusinessLayer.AppLogCatalog.GetColumnNameOverride("AppLog", "Timestamp") ?? "Timestamp";
			ColumnNames[9] = BizElements.BusinessLayer.AppLogCatalog.GetColumnNameOverride("AppLog", "MachineName") ?? "MachineName";
			ColumnNames[10] = BizElements.BusinessLayer.AppLogCatalog.GetColumnNameOverride("AppLog", "AppDomainName") ?? "AppDomainName";
			ColumnNames[11] = BizElements.BusinessLayer.AppLogCatalog.GetColumnNameOverride("AppLog", "FormattedMessage") ?? "FormattedMessage";
			ColumnNames[12] = BizElements.BusinessLayer.AppLogCatalog.GetColumnNameOverride("AppLog", "Status") ?? "Status";
		}

		#endregion
		
		#region Singleton/immutable configuration objects.

		static readonly DbColumnConfiguration[] ImmutableColumnProperties;
		static readonly DbTableConfiguration ImmutableTableProperties;

		private static DbColumnConfiguration[] CreateImmutableColumnProperties()
		{
			return new DbColumnConfiguration[]
			{
				new DbColumnConfiguration(ColumnNames[0], DbType.Int32, typeof(int), false, 0, true, null, 0, true, false, false, "LogID", int.MinValue, int.MaxValue, false, SequenceNameOverrides[0]),
				new DbColumnConfiguration(ColumnNames[1], DbType.AnsiString, typeof(string), true, 1, AutoIncrementOverrides[1] ?? false, null, 256, false, false, false, "Title", null, null, false, SequenceNameOverrides[1]),
				new DbColumnConfiguration(ColumnNames[2], DbType.String, typeof(string), true, 2, AutoIncrementOverrides[2] ?? false, null, 1073741823, false, false, false, "Message", null, null, false, SequenceNameOverrides[2]),
				new DbColumnConfiguration(ColumnNames[3], DbType.AnsiString, typeof(string), true, 3, AutoIncrementOverrides[3] ?? false, null, 32, false, false, false, "ActorID", null, null, false, SequenceNameOverrides[3]),
				new DbColumnConfiguration(ColumnNames[4], DbType.AnsiString, typeof(string), true, 4, AutoIncrementOverrides[4] ?? false, null, 32, false, false, false, "ActorName", null, null, false, SequenceNameOverrides[4]),
				new DbColumnConfiguration(ColumnNames[5], DbType.AnsiString, typeof(string), true, 5, AutoIncrementOverrides[5] ?? false, null, 256, false, false, false, "ObjectType", null, null, false, SequenceNameOverrides[5]),
				new DbColumnConfiguration(ColumnNames[6], DbType.AnsiString, typeof(string), true, 6, AutoIncrementOverrides[6] ?? false, null, 32, false, false, false, "ObjectID", null, null, false, SequenceNameOverrides[6]),
				new DbColumnConfiguration(ColumnNames[7], DbType.AnsiString, typeof(string), true, 7, AutoIncrementOverrides[7] ?? false, null, 32, false, false, false, "Category", null, null, false, SequenceNameOverrides[7]),
				new DbColumnConfiguration(ColumnNames[8], DbType.DateTime, typeof(DateTime), true, 8, AutoIncrementOverrides[8] ?? false, null, 0, false, false, false, "Timestamp", new DateTime(1753, 1, 1), new DateTime(9999, 12, 31), false, SequenceNameOverrides[8]),
				new DbColumnConfiguration(ColumnNames[9], DbType.AnsiString, typeof(string), true, 9, AutoIncrementOverrides[9] ?? false, null, 32, false, false, false, "MachineName", null, null, false, SequenceNameOverrides[9]),
				new DbColumnConfiguration(ColumnNames[10], DbType.AnsiString, typeof(string), true, 10, AutoIncrementOverrides[10] ?? false, null, 256, false, false, false, "AppDomainName", null, null, false, SequenceNameOverrides[10]),
				new DbColumnConfiguration(ColumnNames[11], DbType.AnsiString, typeof(string), true, 11, AutoIncrementOverrides[11] ?? false, null, 1073741823, false, false, false, "FormattedMessage", null, null, false, SequenceNameOverrides[11]),
				new DbColumnConfiguration(ColumnNames[12], DbType.Byte, typeof(byte), false, 12, AutoIncrementOverrides[12] ?? false, null, 0, false, false, false, "Status", byte.MinValue, byte.MaxValue, false, SequenceNameOverrides[12]),
			};
		}

		private static DbTableConfiguration CreateImmutableTableProperties()
		{
			return new DbTableConfiguration
			(
				BizElements.BusinessLayer.AppLogCatalog.GetTableNameOverride("AppLog") ?? "AppLog",
				new BizElements.BusinessLayer.AppLogCatalog(),
				ImmutableColumnProperties,
				new int[] { 0 },
				new string[] { },
				/*is view*/ false
			);
		}
		
		#endregion
		
		#region Constructors.

		/// <summary>
		/// Initializes a new instance of AppLogMeta class.
		/// </summary>
		public AppLogMeta()
			: base(ImmutableTableProperties, null, false)
		{
		}

		/// <summary>
		/// Initializes a new instance of AppLogMeta class.
		/// </summary>
		/// <param name="alias">Object alias. If NULL then it will be equal to the table name.</param>
		public AppLogMeta(string alias)
			: base(ImmutableTableProperties, alias, false)
		{
		}

		/// <summary>
		/// Initializes a new instance of AppLogMeta class.
		/// </summary>
		/// <param name="setPrefixedColumnAliases">Whether to change aliases of all columns so that they start with prefix (usually table name).</param>
		public AppLogMeta(bool setPrefixedColumnAliases)
			: base(ImmutableTableProperties, null, setPrefixedColumnAliases)
		{
		}

		/// <summary>
		/// Initializes a new instance of AppLogMeta class.
		/// </summary>
		/// <param name="alias">Object alias. If NULL then it will be equal to the table name.</param>
		/// <param name="setPrefixedColumnAliases">Whether to change aliases of all columns so that they start with prefix (usually table name).</param>
		public AppLogMeta(string alias, bool setPrefixedColumnAliases)
			: base(ImmutableTableProperties, alias, setPrefixedColumnAliases)
		{
		}

		#endregion

		#region CreateForeignKeys.

		/// <summary>
		/// Initializes an array of relations used by foreign keys.
		/// Only relations to other generated IDbTable classes are created.
		/// </summary>
		protected override DbRelation[] CreateForeignKeys()
		{
			DbRelation[] foreignKeys = new DbRelation[0];
      
			return foreignKeys;
		}

		#endregion

		#region New* methods.
    
		/// <summary>
		/// Creates a new AppLogEntity object.
		/// </summary>
		/// <returns>New entity.</returns>
		public override IEntity NewEntity()
		{
			return new AppLogEntity(this);
		}
    
		/// <summary>
		/// Creates a new EntityReader&lt;AppLogEntity&gt; object.
		/// </summary>
		/// <returns>An instance of EntityReader&lt;AppLogEntity&gt; class.</returns>
		public override IObjectReader NewEntityReader()
		{
			// Use default EntityReader<T>() constructor when targeting SQLite database or when column types are compatible/convertible, but do not exactly match, entity property types.
			return new EntityReader<AppLogEntity>(AppLogEntity.NewEntity);
		}

		#endregion

		#region Clone.

		/// <summary>
		/// Creates another IDbTable object for the same table/view.
		/// </summary>
		/// <param name="cloneAlias">Clone alias.</param>
		/// <returns>Clone.</returns>
		public override IDbTable Clone(string cloneAlias)
		{
			return new AppLogMeta(cloneAlias);
		}

		/// <summary>
		/// Creates another IDbTable object for the same table/view.
		/// </summary>
		/// <param name="cloneAlias">Clone alias.</param>
		/// <param name="setPrefixedAliases">Specifies whether cloned columns will have prefixed aliases.</param>
		/// <returns>Clone.</returns>
		public override IDbTable Clone(string cloneAlias, bool setPrefixedAliases)
		{
			return new AppLogMeta(cloneAlias, setPrefixedAliases);
		}

		#endregion

		#region Columns.
    
		/// <summary>
		/// Gets metadata for 'LogID' column.
		/// </summary>
		public IDbColumn LogID
		{
			get {return this.Columns[0];}
		}
			
		/// <summary>
		/// Gets metadata for 'Title' column.
		/// </summary>
		public IDbColumn Title
		{
			get {return this.Columns[1];}
		}
			
		/// <summary>
		/// Gets metadata for 'Message' column.
		/// </summary>
		public IDbColumn Message
		{
			get {return this.Columns[2];}
		}
			
		/// <summary>
		/// Gets metadata for 'ActorID' column.
		/// </summary>
		public IDbColumn ActorID
		{
			get {return this.Columns[3];}
		}
			
		/// <summary>
		/// Gets metadata for 'ActorName' column.
		/// </summary>
		public IDbColumn ActorName
		{
			get {return this.Columns[4];}
		}
			
		/// <summary>
		/// Gets metadata for 'ObjectType' column.
		/// </summary>
		public IDbColumn ObjectType
		{
			get {return this.Columns[5];}
		}
			
		/// <summary>
		/// Gets metadata for 'ObjectID' column.
		/// </summary>
		public IDbColumn ObjectID
		{
			get {return this.Columns[6];}
		}
			
		/// <summary>
		/// Gets metadata for 'Category' column.
		/// </summary>
		public IDbColumn Category
		{
			get {return this.Columns[7];}
		}
			
		/// <summary>
		/// Gets metadata for 'Timestamp' column.
		/// </summary>
		public IDbColumn Timestamp
		{
			get {return this.Columns[8];}
		}
			
		/// <summary>
		/// Gets metadata for 'MachineName' column.
		/// </summary>
		public IDbColumn MachineName
		{
			get {return this.Columns[9];}
		}
			
		/// <summary>
		/// Gets metadata for 'AppDomainName' column.
		/// </summary>
		public IDbColumn AppDomainName
		{
			get {return this.Columns[10];}
		}
			
		/// <summary>
		/// Gets metadata for 'FormattedMessage' column.
		/// </summary>
		public IDbColumn FormattedMessage
		{
			get {return this.Columns[11];}
		}
			
		/// <summary>
		/// Gets metadata for 'Status' column.
		/// </summary>
		public IDbColumn Status
		{
			get {return this.Columns[12];}
		}
			
		#endregion
    
		#region Foreign keys.
		
		#endregion

		#region Parent entity property name getters.
		
		#endregion

		#region Children.
    
		/// <summary>
		/// Gets tables which reference the current table.
		/// </summary>
		/// <returns>Array of tables or empty array if the current table is not referenced by other objects.</returns>
		public override IDbTable[] GetChildTables()
		{
			return new IDbTable[]
			{
			};
		}

		/// <summary>
		/// Gets relations where current table acts as a parent.
		/// </summary>
		/// <returns>Array of relations or empty array if the current table is not referenced by other objects.</returns>
		public override DbRelation[] GetChildRelations()
		{
			return new DbRelation[]
			{
			};
		}

		#endregion
	}
}
